/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pes_soft.cloud.demo.provider;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pes_soft.cloud.util.stream.StreamResponse;
import com.pes_soft.cloud.util.stream.StreamType;
import com.pes_soft.cloud.util.stream.StreamUtil;

@Controller
public class ProviderController {
	@ResponseBody
	@RequestMapping("/serverProvider")
	public StreamResponse<?> serverProvider() {
		return StreamUtil.createResponse(StreamType.SUCCESS, "I'm spring-cloud-zookeeper-server 2");
	}

	@RequestMapping(value="/hello", method=RequestMethod.GET)
	public String hello(@RequestParam String name) {
		return "Hello!+2 " + name;
	}
	
	@RequestMapping(value="/newUser", method=RequestMethod.GET)
	public UserInServer newUser(@RequestHeader String name, @RequestHeader Integer age) {
		UserInServer user = new UserInServer();
		user.setName(name);
		user.setAge(age);
		
		return user;
	}
	
	@RequestMapping(value="/jsonUser", method=RequestMethod.POST)
	public String jsonUser(@RequestBody UserInServer user) {
		return "Hello! " + user.getName() + ", " + user.getAge();
	}
}